home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: jcf3820@silver.sdsmt.edu (James Foster)
- Newsgroups: comp.lang.c,comp.lang.c.moderated
- Subject: Re: 8 Queens prog help
- Followup-To: comp.lang.c,comp.lang.c.moderated
- Date: 20 Apr 1996 13:22:16 -0500
- Organization: South Dakota School of Mines and Technology
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4lba0o$lg3@solutions.solon.com>
- References: <4l87ud$73u@solutions.solon.com>
- NNTP-Posting-Host: solutions.solon.com
- X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
-
- Mike Mitchell (72724.2067@CompuServe.COM) wrote:
- : Hi All!
- :
- : Need some C help this week. I'm currently working on a program
- : called "Eight Queens". Basically, I have to place 8 queen chess
- : pieces on an 8x8 chess board without them checking one another.
-
- I had to program something similar in Data Structures, except that the
- user got to put in how many queens and rooks to place on a board and we
- had to find how many possible solutions. However, the algorithm is pretty
- much the same. Just follow this and you should be fine.
-
- Try to put a queen on the board.
-
- 1. Succeed
- -recursive call
- move next row
- decrease # of queens
- save the column position
-
- 2. Failed
- - return to previous call by decrementing the row and undo the attacked
- position (see below). Get the column that was saved and increment it
- so that you can continue where you left off.
-
- To see if its valid to put a queen in a spot (won't be attacked by another
- queen) use arrays to represent the columns, positive and negative
- diagnols.. if its equal to 0 (you initialize them to zero) its a good
- spot, and then mark that spot with a -1. Remeber to set the spot the last
- queen was placed back to 0 if you fail and return to the previous call.
-
- --
- ___
- / 0 0 \
- ========oo0=(_)=0oo===========
- |\--------------------------/|
- || Chad Foster ||
- || jcf3820@silver.sdsmt.edu ||
- || (605) 394-2768 ||
- |/------.ooo0---------------\|
- ========( )=0ooo.===========
- \ ( ( )
- \_) ) /
- (_/
-